# Time-stamp: <04 May 00 18:01:55 giron1>

=head1 NAME

 SIDL_ACTIONS - SIDL actions parsing package

=head1 SYNOPSIS

 use SIDL_ACTIONS;

=head1 DESCRIPTION

This package manipulates a SIDL Actions hash.

=head1 AUTHOR

 Stephan Rapp, Franck Giron
 $Id: SIDL_ACTIONS.pm,v 1.1 2007/10/08 09:26:03 schweitz Exp $

=head1 LOG

 $Log: SIDL_ACTIONS.pm,v $
 Revision 1.1  2007/10/08 09:26:03  schweitz
 version 2.4, lib vergessen

 Revision 1.1  2000/05/12 15:00:56  giron1
 First package version


=cut

package SIDL_ACTIONS;

#----------------------------------------------------------------------
# perl packages
#----------------------------------------------------------------------

use Exporter ();

@ISA = qw(Exporter);

# Functions to export

@EXPORT = qw(fixtargets writeactions);

sub fixtargets {
  my ($nodeid,$Actions_ref) = @_;

  my (@actionkeys) = keys %$Actions_ref;

  foreach $key (@actionkeys) {
    $Actions_ref->{$key}{nodeid} = $nodeid if (!$Actions_ref->{$key}{nodeid});
  }
}

sub writeactions {
  my ($filename,$Actions_ref) = @_;

  open ACTIONFILE, ">$filename" 
    or die "could not open $filename for writing\n";

  my (@actionkeys) = keys %$Actions_ref;
  foreach $key (sort @actionkeys) {
    if ($key){
      next if (not defined($Actions_ref->{$key}{type}));
      if ($Actions_ref->{$key}{type} eq 'avc') {
	print ACTIONFILE "avc" . "\t" .
	  "$key\t" . 
	    $Actions_ref->{$key}{nodeid} . "\t" . 
	      $Actions_ref->{$key}{ctype} . "\t" .
		$Actions_ref->{$key}{subunittype} . "\t" . 
		  $Actions_ref->{$key}{subunitid} . "\t" .
		    $Actions_ref->{$key}{opcode};
	my($operand);
	foreach $operand (@{$Actions_ref->{$key}{operand}}) {
	  print ACTIONFILE "\t$operand";
	}
	print ACTIONFILE "\n";
      }
      elsif ($Actions_ref->{$key}{type} eq 'win') {
	print ACTIONFILE "win" . "\t" .
	  "$key\t" . 
	    $Actions_ref->{$key}{nodeid} . "\t" . 
	      $Actions_ref->{$key}{handle} . "\t" .
		$Actions_ref->{$key}{command} . "\t" . 
		  $Actions_ref->{$key}{wparam} . "\t" .
		    $Actions_ref->{$key}{lparam};
	print ACTIONFILE "\n";
      }
    }
  }
  close ACTIONFILE;    
}

1;

